home *** CD-ROM | disk | FTP | other *** search
- //***********************************************************************
- //
- // DLGDEMO1.CPP
- //
- //***********************************************************************
-
- #include <afxwin.h>
- #include "Resource.h"
- #include "DlgDemo1.h"
-
- #define FONTHEIGHT 72
-
- CMyApp myApp;
-
- /////////////////////////////////////////////////////////////////////////
- // CMyApp member functions
-
- BOOL CMyApp::InitInstance ()
- {
- m_pMainWnd = new CMainWindow;
- m_pMainWnd->ShowWindow (m_nCmdShow);
- m_pMainWnd->UpdateWindow ();
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////
- // CMainWindow message map and member functions
-
- BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
- ON_WM_ERASEBKGND ()
- ON_WM_PAINT ()
- ON_COMMAND (IDM_OPTIONS_EXIT, OnOptionsExit)
- ON_COMMAND (IDM_OPTIONS_ABOUT, OnOptionsAbout)
- END_MESSAGE_MAP ()
-
- CMainWindow::CMainWindow ()
- {
- Create (NULL, "DlgDemo1", WS_OVERLAPPEDWINDOW, rectDefault, NULL,
- MAKEINTRESOURCE (IDR_MAINFRAME));
- }
-
- BOOL CMainWindow::OnEraseBkgnd (CDC* pDC)
- {
- CRect rect;
- GetClientRect (&rect);
- DoGradientFill (pDC, &rect);
- return TRUE;
- }
-
- void CMainWindow::OnPaint ()
- {
- CRect rect;
- GetClientRect (&rect);
-
- CPaintDC dc (this);
- DoDrawText (&dc, &rect);
- }
-
- void CMainWindow::OnOptionsExit ()
- {
- SendMessage (WM_CLOSE, 0, 0);
- }
-
- void CMainWindow::OnOptionsAbout ()
- {
- CDialog dlg (IDD_ABOUTDLG, this);
- dlg.DoModal ();
- }
-
- void CMainWindow::DoGradientFill (CDC* pDC, CRect* pRect)
- {
- CPen* pPen[64];
- for (int i=0; i<64; i++)
- pPen[i] = new CPen (PS_SOLID, 1, RGB (0, 0, 255 - (i * 4)));
-
- int nWidth = pRect->Width ();
- int nHeight = pRect->Height ();
-
- for (i=0; i<nHeight; i++) {
- pDC->SelectObject (pPen[(i * 63) / nHeight]);
- pDC->MoveTo (0, i);
- pDC->LineTo (nWidth, i);
- }
-
- pDC->SelectStockObject (BLACK_PEN);
- for (i=0; i<64; i++)
- delete pPen[i];
- }
-
- void CMainWindow::DoDrawText (CDC* pDC, CRect* pRect)
- {
- CFont font;
- int nHeight = -((pDC->GetDeviceCaps (LOGPIXELSY) * FONTHEIGHT) / 72);
-
- font.CreateFont (nHeight, 0, 0, 0, FW_BOLD, TRUE, 0, 0,
- DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
- DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Times New Roman");
-
- pDC->SetBkMode (TRANSPARENT);
- pDC->SetTextColor (RGB (255, 255, 255));
-
- CFont* pOldFont = pDC->SelectObject (&font);
- pDC->DrawText ("Hello, MFC", -1, pRect, DT_SINGLELINE | DT_CENTER |
- DT_VCENTER);
-
- pDC->SelectObject (pOldFont);
- }
-